// src/api/userService.ts
import request from './axiosInstance';
import type { Order, Address } from '../types/user';

export const getUserInfo = async () => {
  const response = await request.get('/users/info');
  return response.data;
};

export const getUserOrders = async (status?: string) => {
  const response = await request.get(`/orders?status=${status}`);
  return response.data;
};

// 地址管理相关API
export const getAddresses = async (): Promise<Address[]> => {
  const response = await request.get('/addresses');
  return response.data; // 确保这里返回的是正确的数据结构
};

export const createAddress = async (address: Omit<Address, 'id' | 'userId' | 'createdAt' | 'updatedAt'>) => {
  const response = await request.post('/addresses', address);
  return response.data;
};

export const updateAddress = async (id: number, address: Partial<Address>) => {
  const response = await request.put(`/addresses/${id}`, address);
  return response.data;
};

export const deleteAddress = async (id: number) => {
  const response = await request.delete(`/addresses/${id}`);
  return response.data;
};

export const setDefaultAddress = async (id: number) => {
  const response = await request.patch(`/addresses/${id}/default`);
  return response.data;
};